package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Description:
 *
 * @Author: xiongzhenhui
 * @Create: 2025/8/9 9:52
 * @Version: 1.0
 */
@RestController
public class OrderInfoController {
    @Autowired
    OrderInfoService orderInfoService;
    @RequestMapping("/getOrderByJe")
    public JSONObject getOrderByJe(){
        List<Map> list = orderInfoService.getOrderByJe();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        for (Map map : list) {
            jsonObject.put("data",map.get("je"));
        }
        return jsonObject;
    }
    @RequestMapping("/getOrderInfoByZb")
    public JSONObject getOrderInfoByZb(){
        List<Map> list = orderInfoService.getOrderInfoByZb();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONArray data = new JSONArray();
        for (Map map : list) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",map.get("name"));
            jsonObject1.put("value",map.get("zb"));
            data.add(jsonObject1);
        }
        jsonObject.put("data",data);
        return jsonObject;
    }
    @RequestMapping("/getOrderInfoByNum")
    public JSONObject getOrderInfoByNum(){
        List<Map> list = orderInfoService.getOrderInfoByNum();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject data = new JSONObject();
        JSONArray columns = new JSONArray();
        JSONObject col1 = new JSONObject();
        col1.put("name","机构");
        col1.put("id","start_org_name");
        columns.add(col1);

        JSONObject col2 = new JSONObject();
        col2.put("name","完运里程");
        col2.put("id","actual_distance");
        columns.add(col2);

        JSONObject col3 = new JSONObject();
        col3.put("name","完运次数");
        col3.put("id","actual_num");
        columns.add(col3);

        JSONObject col4 = new JSONObject();
        col4.put("name","完运时长");
        col4.put("id","actual_hour");
        columns.add(col4);

        JSONObject col5 = new JSONObject();
        col5.put("name","每次平均时长");
        col5.put("id","avg_hour");
        columns.add(col5);

        JSONObject col6 = new JSONObject();
        col6.put("name","每次平均里程");
        col6.put("id","avg_distance");
        columns.add(col6);

        data.put("columns",columns);
        JSONArray rows = new JSONArray();
        for (Map map : list) {
            JSONObject row = new JSONObject();
            row.put("start_org_name",map.get("start_org_name"));
            row.put("actual_distance",map.get("actual_distance"));
            row.put("actual_num",map.get("actual_num"));
            row.put("actual_hour",map.get("actual_hour"));
            row.put("avg_hour",map.get("avg_hour"));
            row.put("avg_distance",map.get("avg_distance"));
            rows.add(row);
        }
        data.put("rows",rows);

        jsonObject.put("data",data);
        return jsonObject;
    }
    @RequestMapping("/getOrderInfoBySl")
    public JSONObject getOrderInfoBySl(){
        List<Map> list = orderInfoService.getOrderInfoBySl();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject data = new JSONObject();
        JSONArray mapData = new JSONArray();
        for (Map map : list) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",map.get("name"));
            jsonObject1.put("value",map.get("num"));
            JSONArray tooltipValues = new JSONArray();
            tooltipValues.add(map.get("je"));
            jsonObject1.put("tooltipValues",tooltipValues);
            mapData.add(jsonObject1);
        }
        data.put("mapData",mapData);
        data.put("valueName","运单数量");
        JSONArray tooltipNames = new JSONArray();
        tooltipNames.add("运单金额");
        data.put("tooltipNames",tooltipNames);
        JSONArray tooltipUnits = new JSONArray();
        tooltipUnits.add("元");
        data.put("tooltipUnits",tooltipUnits);
        jsonObject.put("data",data);
        return jsonObject;
    }
    @RequestMapping("/getOrderInfoByZs")
    public JSONObject getOrderInfoByZs(){
        List<Map> list = orderInfoService.getOrderInfoByZs();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONArray data = new JSONArray();
        for (Map map : list) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name","接单数");
            jsonObject1.put("value",map.get("jd"));
            data.add(jsonObject1);
            JSONObject jsonObject2 = new JSONObject();
            jsonObject2.put("name","发单数");
            jsonObject2.put("value",map.get("fd"));
            data.add(jsonObject2);
            JSONObject jsonObject3 = new JSONObject();
            jsonObject3.put("name","完成运单数");
            jsonObject3.put("value",map.get("wc"));
            data.add(jsonObject3);
        }
        jsonObject.put("data",data);
        return jsonObject;
    }
    @RequestMapping("/getOrderInfoByWc")
    public JSONObject getOrderInfoByWc(){
        List<Map> list = orderInfoService.getOrderInfoByWc();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject data = new JSONObject();
        JSONArray categories = new JSONArray();
        for (Map map : list) {
            categories.add(map.get("name"));
        }
        data.put("categories",categories);
        JSONArray series = new JSONArray();
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name","完成数量");
        JSONArray jsonArrayX = new JSONArray();
        for (Map map : list) {
            jsonArrayX.add(map.get("num"));
        }
        series.add(jsonObject1);
        jsonObject1.put("data",jsonArrayX);
        data.put("series",series);
        jsonObject.put("data",data);
        return jsonObject;
    }
}
